package com.qdev.apps.core.webwork.interceptor;

import com.opensymphony.xwork.Action;
import com.opensymphony.xwork.ActionInvocation;
import com.opensymphony.xwork.interceptor.Interceptor;
import com.qdev.apps.core.webwork.action.Protected;

/**
 * @author   Quake Wang
 * @since    2004-7-16
 * @version $Revision: 1.1 $
 */
public class PermissionInterceptor implements Interceptor {
    public static final String NOPERMISSION = "nopermission";
    
    public void destroy() {

    }

    public void init() {

    }

    public String intercept(ActionInvocation invocation) throws Exception {
        Action action = invocation.getAction();
        if(action instanceof Protected) {
            if(!((Protected) action).hasPermission()){
                return NOPERMISSION;
            }
        }
        return invocation.invoke();
    }

}
